package com.cuit.zuke.consumer.service.impl;

import com.cuit.zuke.common.util.Result;
import com.cuit.zuke.common.vo.WeeklyDataVo;
import com.cuit.zuke.consumer.mapper.UserMapper;
import com.cuit.zuke.consumer.pojo.User;
import com.cuit.zuke.consumer.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@SuppressWarnings("all")
@Service
public class UserServiceImpl implements UserService {

    private static int userTotal = 0;

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> queryUserList(int currentPage, int pageSize) {
        return userMapper.queryUserList(currentPage, pageSize);
    }

    @Override
    public int queryTotal() {
        return userTotal;
    }

    @Override
    public User queryUserById(String userId) {
        return userMapper.queryUserById(userId);
    }

    @Override
    public void updateStatus(String userId, int userStatus) {
        userMapper.updateStatus(userId, userStatus);
    }

    @Override
    public User queryUserByPhone(String userPhone) {
        return userMapper.queryUserByPhone(userPhone);
    }

    @Override
    public String queryMaxUserId() {
        return userMapper.queryMaxUserId();
    }

    @Override
    public void insertUser(String userId, String userPhone, String password, int status, String userName, String userCreatTime) {
        userMapper.insertUser(userId, userPhone, password, status, userName, userCreatTime);
    }

    @Override
    public void updateUer(User user) {
        userMapper.updateUer(user);
    }

    @Override
    public Map<String, List<?>> getDailyUserData() {
        List<WeeklyDataVo> dataList = userMapper.getDailyUserData();
        List<String> weekend = dataList.stream().map(WeeklyDataVo::getWeekend).collect(Collectors.toList());
        List<Integer> count = dataList.stream().map(WeeklyDataVo::getCount).collect(Collectors.toList());
        Map<String, List<?>> map = new HashMap<>();
        map.put("weekend", weekend);
        map.put("count", count);
        return map;
    }

    @Override
    public Result getWeeklyUserRegData() {
        List<WeeklyDataVo> regData = userMapper.getLastlySevenDaysUserRegData();
        userTotal = userMapper.queryTotal();
        return Result.ok().put("regData", regData).put("userTotal", userTotal);
    }
}
